<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places&sensor=true"></script>

<script >

var map;
var flag;
var service;
var infowindow;
var request;
function initialize() {
  var pyrmont = new google.maps.LatLng(23.492, 111.315);

  map = new google.maps.Map(document.getElementById('map'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: pyrmont,
      zoom: 12
    });

//  request = {
//    location: pyrmont,
//    radius: '5000',
//    query: 'restaurant'//restaurant,store,travel
 // };
//createMarker(pyrmont);
//  service = new google.maps.places.PlacesService(map);
//  service.textSearch(request, callback);
 google.maps.event.addListener(map, 'bounds_changed',refresh);

}
function ff(ss){
//google.maps.event.addListener(map, 'bounds_changed',refresh);
flag=ss;
}



function refresh(){

request = {
    location: map.getCenter(),
    radius: '100',
	query:"travel"
	
	/*if(flag==1){
	request = {
    location: map.getCenter(),
    radius: '100',
	query:"ATM"
	}
	if(flag==2){
		request = {
    location: map.getCenter(),
    radius: '100',
	query:"restaurant"
	}}
	if(flag==3){
		request = {
    location: map.getCenter(),
    radius: '100',
	query:"filling station"
	}}
	if(flag==4){
		request = {
    location: map.getCenter(),
    radius: '100',
	query:"toilet"
	}}
	 if(flag==5){
		request = {
    location: map.getCenter(),
    radius: '100',
	query:"travel"
	}}
		if(flag==6){
		request = {
    location: map.getCenter(),
    radius: '100',
	query:"MALL"
	}}*/
//restaurant,store,travel,ATM,filling station,Bus station,toilet,MALL,bank
  };



//createMarker(pyrmont);
	
  service = new google.maps.places.PlacesService(map);
  service.textSearch(request, callback);//textSearch

}

var searchPoints=[];
function callback(results, status) {
	//alert(results[0].geometry.location.lat());
	if(results==null){
		//alert("�Ҳ���");
	}
if (status == google.maps.places.PlacesServiceStatus.OK) {
	if(searchPoints!=null){
		hidesearchPointMarker();
	}
	var temp=results.length;
	if(temp>15){
		temp=15;
	}else{
		temp=results.length;
	}

    for (var i = 0; i < temp; i++) {
		
		//alert(results[0].geometry.location.lat());
      createMarker(results[i]);
    }
}else 
if(status==google.maps.places.PlacesServiceStatus.INVALID_REQUEST){

	//alert("������Ч");
}else if(status==google.maps.places.PlacesServiceStatus.OVER_QUERY_LIMIT){
	//alert("��ҳ�ѳ������������");
  
}else if(status==google.maps.places.PlacesServiceStatus.REQUEST_DENIED){
	//alert("��ҳ�ѽ�ֹʹ�õط���Ϣ����");
  
}else if(status==google.maps.places.PlacesServiceStatus.ZERO_RESULTS_RESULTS){
	//alert("�Ҳ������ڴ�������κν��");

}else if(status==google.maps.places.PlacesServiceStatus.ERROR){
	//alert("���� Google ������ʱ��������");
  }
}



function createMarker(aaa){
	var marker = new google.maps.Marker({
			position: aaa.geometry.location
			
		});
		searchPoints.push(marker);
		infowindow = new google.maps.InfoWindow();
		var content = '<strong>' + aaa.name + '</strong><br />';
		content += "<a href=http://543000.114133.com/>网上订购</a>";
		content += "<div onclick='Android.phoneCall(12356444);'>电话订购 </div>" ;
// Adding the content to the InfoWindow
infowindow.setContent(content);
// Opening the InfoWindow
	openMarker(marker,content);
	marker.setMap(map);
}

function hidesearchPointMarker(){
	if(searchPoints){
		for(var i in searchPoints){
			searchPoints[i].setMap(null);
		}
		searchPoints=[];
		
	}
}

function openMarker(marker,text){
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(text);
	        infowindow.open(map,marker);
		});
	}
/*
(function() {
// Defining some global variables
var map, geocoder, marker, infowindow;
window.onload = function() {
// Creating a new map
var options = {
zoom: 3,
center: new google.maps.LatLng(23.492, 111.315),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
// Getting a reference to the HTML form
var form = document.getElementById('addressForm');
// Catching the forms submit event
form.onsubmit = function() {
// Getting the address from the text input
var address = document.getElementById('address').value;
//new google.maps.places.Autocomplete(address);
// Making the Geocoder call
getCoordinates(address);
// Preventing the form from doing a page submit
return false;
}
}
// Create a function the will return the coordinates for the address
function getCoordinates(address) {
// Check to see if we already have a geocoded object. If not we create one
if(!geocoder) {
geocoder = new google.maps.Geocoder();
}
// Creating a GeocoderRequest object
var geocoderRequest = {
address: address
}
// Making the Geocode requestCHAPTER 10 �� LOCATION, LOCATION, LOCATION222
geocoder.geocode(geocoderRequest, function(results, status) {
// Check if status is OK before proceeding
if (status == google.maps.GeocoderStatus.OK) {
// Center the map on the returned location
map.setCenter(results[0].geometry.location);
// Check to see if we've already got a Marker object
if (!marker) {
// Creating a new marker and adding it to the map
marker = new google.maps.Marker({
map: map
});
}
// Setting the position of the marker to the returned location
marker.setPosition(results[0].geometry.location);
// Check to see if we've already got an InfoWindow object
if (!infowindow) {
// Creating a new InfoWindow
infowindow = new google.maps.InfoWindow();
}
// Creating the content of the InfoWindow to the address
// and the returned position
var content = '<strong>' + results[0].formatted_address + '</strong><br />';
content += 'Lat: ' + results[0].geometry.location.lat() + '<br />';
content += 'Lng: ' + results[0].geometry.location.lng();
// Adding the content to the InfoWindow
infowindow.setContent(content);
// Opening the InfoWindow
infowindow.open(map, marker);
}
});
}
})();*/
</script>

</head>

<body onload="initialize();">
<div id="map" style="height:100%;width:100%;"></div>
<div >
	<input id="address" type="textbox" value=""/>
	<input type="button" value="ti" onclick="ff(2);" />
</div>
</body>

</html>
 




